import thread

class Algorithm(object):

    def __init__(self, originalHashCode, alphabet, isThreaded, hashCode):
	self.originalHashCode = originalHashCode
	self.alphabet = alphabet
	self.isThreaded = isThreaded
	self.hashCode = hashCode

    def bruteForce(self):
		for dic_entry in self.alphabet:
			if not self.isThreaded:
				self._compute(dic_entry)
			else:
				thread.start_new_thread(self._compute, (dic_entry, ))
		return

    def _compute(self, dic_entry):
		dicHashCode = self.hashCode.getHash(dic_entry)
		if dicHashCode == self.originalHashCode:
			print "%s = %s matches requested hash code with algorithm %s" % (dic_entry, dicHashCode, self.hashCode.name())
		else:
			print "%s = %s not matching requested hash code with algorithm %s" % (dic_entry, dicHashCode, self.hashCode.name())
